##### My (demuredemeanor) muttrc
# Uses tabstop=4; shiftwidth=4 tabs; foldmarker={{{,}}};
# https://notabug.org/demure/dotfiles
# legacy repo http://github.com/demure/dotfiles
# vim:set syntax=muttrc:

## This is heavily inspired by Mark H. Nichols's post
# http://zanshin.net/2015/01/19/teaching-a-homely-mutt-new-tricks/
#
# which in turn was inspired by Steve Losh's post
# http://stevelosh.com/blog/2012/10/the-homely-mutt/
#
# Aside from using my accounts, and eventually a few tweaks,
# I am /not/ using OS X's keychain...
# I am using pass now, which is working quite well
# https://github.com/sup-heliotrope/sup/wiki/Securely-Store-Password

### Paths ### {{{ 
set folder            = ~/.mail                # mailbox location
set alias_file        = ~/.mutt/alias          # where to store aliases
set header_cache      = ~/.mutt/cache/headers  # where to store headers
set message_cachedir  = ~/.mutt/cache/bodies   # where to store bodies
set certificate_file  = ~/.mutt/cerficates     # where to store certs
set mailcap_path      = ~/.mutt/mailcap        # entries for filetypes
set tmpdir            = ~/.mutt/temp           # where to keep temp files
set signature         = ~/.mutt/sig            # my signature file
### End Pathes ### }}}

### Basic Options ### {{{ 
set wait_key = no        # shut up, mutt
set mbox_type = Maildir  # mailbox type
set timeout = 3          # idle time before scanning
set mail_check = 0       # minimum time between scans
unset move               # gmail does that
set delete               # don't ask, just do
unset confirmappend      # don't ask, just do!
set quit = ask-no        # don't ask, just do !!
unset mark_old           # read/new is good enough for me
set beep_new             # bell on new mails
set pipe_decode          # strip headers and eval mimes when piping
set thorough_search      # strip headers and eval mimes before searching

set sort_alias = alias

auto_view text/html
alternative_order text/plain text/html
## Adding flowed, because it is a good-ness? http://joeclark.org/ffaq.html
set text_flowed = yes # Generate text/plain; format=flowed attachments.

set allow_ansi

subscribe ahashop
### End Basic ### }}}

### Sourcing ### {{{
source ~/.mutt/alias
source ~/.mutt/crypto.muttrc
### End Sourcing ### }}}

### Color Scheme ### {{{ 
#source ~/.mutt/themes/comidia.muttrc
#source ~/.mutt/themes/vombatidae.muttrc
#source ~/.mutt/themes/tomorrow-night.muttrc
#source ~/.mutt/themes/mutt-colors-solarized-dark-16.muttrc
#source ~/.mutt/themes/mutt-colors-solarized-light-16.muttrc
### End Color ### }}}

### Sidebar Patch ### {{{ 
set sidebar_visible = yes 
set sidebar_delim   = ' | '
set sidebar_width   = 25 
# set sidebar_delim_chars = "./"
color sidebar_new  yellow default
### End Sidebar ### }}}

### Status Bar ### {{{ 
set status_chars   = " *%A"

## status_format - format of summary on the current folder in the index
## meta strings:
##  -----f-h---lmn-p-rst-v----  lower case letters (10)
##  ------------M----------X--  upper case letters (02)
## %d      the number of messages with the flag 'delete'  (v64)
## %f      the full pathname of the current mailbox
## %h      local hostname
## %l      size (in bytes) of the current mailbox
## %m      the number of messages in the mailbox
## %M      the number of messages shown (i.e., which match the current limit)
## %n      number of new messages in the mailbox
## %p      number of postponed messages
## %s      current sorting mode
## %r      modified/read-only/won't-write/attach-message indicator-status_chars
## %t      number of tagged messages
## %v      Mutt version string
## %>X     right justify the rest of the string and pad with "X"
## %|X     pad to the end of the line with "X"
##
## %?<sequence_char>?<optional_string>? optionally print string, if>0
##
## Examples:
#set status_format="%v: %f (%s) [%?M/?%m]  [flags:%?t tagged,?%n new%?p post?]"
#set status_format="%v: %f (%s) [%?M/?%m]  [flags:%?t tagged,?%n new]"
#set status_format="%v: %f (%s) [%M/%m]\n[flags:n=%n,D=%d,t=%t,!=%F]"
#set status_format="%v: %f (%s) [%M/%m]  [flags:n=%n,t=%t]"
#set status_format="%v:    (%s) [%M/%m]  [flags:n=%n,t=%t]"
#set status_format="%v:    (%s) [%M/%m]  [flags:n:%n,t:%t,p:%p]"
#set status_format="%v:    (%s) [%M/%m]  [flags:%?02n new?,t:%t]"
#set status_format="%v: %f (%s) [%M/%m]  [flags:%n new,%?t tagged?]"
#set status_format="%v: %f (%s) [%M/%m;%l bytes]  [N=%n,*=%t,post=%p]"
#set status_format="%v: %f (%s) [%M/%m] [N=%n,*=%t,post=%p,new=%b]"
#set status_format=" Msgs=%M(%m) [N=%n,O=%o,*=%t,p=%p] %> %r (%P) %h:%f [%l] (%s/%S) (%v) "

#set status_format  = "Folder: %f : %r%m messages%?n? (%n new)?%?d? (%d to delete)?%?t? (%t tagged)? %>-%?p?( %p postponed )? : "
set status_on_top = yes
set status_format  = "Folder: %f : %r%n new (%m messages)%?d? (%d to delete)?%?t? (%t tagged)? %>-%?p?( %p postponed )? : "
### End Status Bar ### }}}

### Header Options ### {{{ 
ignore *                               # ignore all headers
unignore from: to: cc: date: subject:  # show only these
unhdr_order *                          # some distros order things
hdr_order from: to: cc: date: subject: # and in this order
### End Header ### }}}

### Account Settings ### {{{ 
## Multiple account setup. 

## Default inbox.
set spoolfile = "+sdf/INBOX"
source ~/.mutt/accounts/sdf.muttrc

## Set account specific options on folder change
folder-hook emu/*         source ~/.mutt/accounts/emu.muttrc
folder-hook sdf/*         source ~/.mutt/accounts/sdf.muttrc
folder-hook gmail/*       source ~/.mutt/accounts/gmail.muttrc
folder-hook local/*       source ~/.mutt/accounts/local.muttrc

## Make sent show recipient
## Doesn't like this regex?
#folder-hook   *[sS]ent* 'set index_format="%2C | %Z [%d] %-30.30t (%-4.4c) %s"'
#folder-hook ! *[sS]ent* 'set index_format="%2C | %Z [%d] %-30.30F (%-4.4c) %s"'

## Mailboxes to show in the sidebar.
mailboxes "+-- sdf ------------" \
		  +sdf/INBOX \
		  +sdf/Drafts \
		  +sdf/Sent \
		  "+-- gmail ----------" \
		  +gmail/INBOX \
		  +gmail/Archives \
		  +gmail/drafts \
		  +gmail/sent \
		  ~/.mail/gmail/Trash \
		  "+-- emu ------------" \
          +emu/INBOX \
          +emu/archive \
          +emu/drafts \
          +emu/sent \
          "+-- local ----------" \
          /var/spool/mail/$USER \
### End Account }}}

### Index View Options ### {{{ 
set date_format = "%m.%d.%y"
set index_format = "[%Z] %D %-20.20F %s"
set sort = threads                         # like gmail
set sort_aux = reverse-last-date-received  # like gmail
set uncollapse_jump                        # don't collapse on an unread message
set sort_re                                # thread based on regex
set reply_regexp = "^(([Rr][Ee]?(\[[0-9]+\])?: *)?(\[[^]]+\] *)?)*"
### End Index  View ### }}}

### Index Key Bindings ### {{{ 
bind index gg         first-entry
bind index G          last-entry

bind index R          group-reply
bind index <tab>      sync-mailbox
bind index <space>    collapse-thread

## Ctrl-R to mark all as read
macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "mark all messages as read"

## Sync email
macro index O "<shell-escape>offlineimap<enter>"           "run offlineimap to sync all mail"
macro index o "<shell-escape>offlineimap -qf INBOX<enter>" "run offlineimap to sync inbox"

## Saner copy/move dialogs
macro index C "<copy-message>?<toggle-mailboxes>" "copy a message to a mailbox"
macro index M "<save-message>?<toggle-mailboxes>" "move a message to a mailbox"

### End Index Key ### }}}

### Sidebar Navigation ### {{{ 
bind index,pager <down>    sidebar-next
bind index,pager <up>      sidebar-prev
bind index,pager <right>   sidebar-open
### End Sidebar Nav ### }}}

### Pager View Settings ### {{{ 
set pager_index_lines = 10  # number of lines to show
set pager_context = 3       # number of context lines to show
set pager_stop              # don't go to the next message automatically
set menu_scroll             # scroll in menus
set tilde                   # show tildes like in vim
unset markers               # no ugly plus signs

set quote_regexp = "^( {0,4}[>|:#%]| {0,4}[a-z0-9]+[>|]+)+"
alternative_order text/plain text/enriched text/html

## Pager Key Bindings
bind pager k   previous-line
bind pager j   next-line
bind pager gg  top
bind pager G   bottom

bind pager R   group-reply

## View attachments properly.
bind attach <return> view-mailcap

## Handle URLs.
macro pager \Cu "|urlview<enter>" "call urlview to open links"
### End Pager View ### }}}

### Compose View Options ### {{{ 
set realname = "demure demeanor"                 # who am I?
set envelope_from                                # which from?
set sig_dashes                                   # dashes before sig
set autoedit
set edit_headers                                 # show headers when composing
set fast_reply                                   # skip to compose when replying
set askcc                                        # ask for CC:
set fcc_attach                                   # save attachments with the body
set mime_forward = ask-no                        # forward attachments as attachments
# unset mime_forward                               # forward attachments as a part of body
set forward_format = "Fwd: %s"                   # format of subject when forwarding
set forward_decode                               # decode when forwarding
set attribution = "On %d, %n wrote:"             # format of quoting header
set reply_to                                     # reply to Reply to: field
set reverse_name                                 # reply as whoever it was to
set include                                      # include message in reply
set forward_quote                                # include message in forwards

set editor = "vim +:silent+?^$"                  # use terminal Vim to compose email
set text_flowed = yes                            # eliminate odd line breaks
# set editor = "vim -c 'set spell spelllang=en' -c 'setlocal fo+=aw' +:silent+?^$"

## This is were the default pgp binding lives...
## Postpone message
#bind compose p postpone-message
#bind index p recall-message

# Vanilla Searching
# / works just like Vim, use `n` to go to next, 'N' to go to previous
bind index N search-opposite
bind pager N search-opposite

# Vanilla Limiting
# `l` + pattern
macro index a "<limit>all\n" "show all messages (undo limit)"
### End Compose View ### }}}
